﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using URIDecoder;

namespace ConfigWindows
{
    public partial class DownloaderControl : UserControl
    {
        public Downloader Downloader { get; set; }
        public DownloaderControl(Downloader d)
        {
            Downloader = d;
            InitializeComponent();
            this.textBox1.Text = Downloader.Name;
            this.textBox2.Text = Downloader.FileName;
            this.textBox3.Text = Downloader.ArgumentsFormat;
        }
        public void SetDefaultDownloader(bool isDefault)
        {
            this.DefaultDownloader.Enabled = false;
            this.DefaultDownloader.Checked = isDefault;
            this.DefaultDownloader.Enabled = true;
        }
        public event EventHandler BecomeDefault;
        private void DefaultDownloader_CheckedChanged(object sender, EventArgs e)
        {
            if (this.DefaultDownloader.Enabled)
                if (DefaultDownloader.Checked) BecomeDefault(this, EventArgs.Empty);
        }
        public void Save()
        {
            Downloader.Name = this.textBox1.Text;
            Downloader.FileName = this.textBox2.Text;
            Downloader.ArgumentsFormat = this.textBox3.Text;
            if (this.DefaultDownloader.Checked) BecomeDefault(this, EventArgs.Empty);
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            this.groupBox1.Text = textBox1.Text;
        }
    }
}
